﻿
using Api.transaction.engine.stock;
using HBase;
using HBase.db;
using hCommand;
using System;
using System.Collections;
using System.Collections.Generic;

namespace Persistence {
    public class WMSTransactionFacade {

        static CsdCsMoveEngine csdCsMoveEngine = new CsdCsMoveEngine();

        static DooCase dooEngine = new DooCase();

        static CsdOutEngine outDetEngine = new CsdOutEngine();
        static CsdSplitEngine splitDetEngine = new CsdSplitEngine();
        static CsdSaveEngine changeCSDEngine = new CsdSaveEngine();
       
        static PkStockEngine pkStockEngine = new PkStockEngine();


        static PkCSAuto pkEngine = new PkCSAuto();
        static PkFinshEngine pkFinshEngine = new PkFinshEngine();
        static Csd2CsEngine csd2CsEngine = new Csd2CsEngine();
        static CsdBackEngine csd21Engine = new CsdBackEngine();

        static StockAddBSEngine<CoreStock> stockAddBSEngine = new StockAddBSEngine<CoreStock>();


        static One2ManyEngine one2ManyEngine = new One2ManyEngine();
        static LocEngine locEngine=new LocEngine();

        static BatchLocAreaEngine batchLocAreaEngine= new BatchLocAreaEngine();

        public static TransRes doBatchLocAreaEngine(List<long> ids,  long areaId) {
            return batchLocAreaEngine.doWork(delegate () { batchLocAreaEngine.ids = ids; batchLocAreaEngine.areaId = areaId; });
        }
        public static TransRes doLocEngine(long id,int ActiveStatus,long areaId) {
            return locEngine.doWork(delegate () { locEngine.id = id; locEngine.ActiveStatus = ActiveStatus; locEngine.areaId = areaId; });
        }

        public static TransRes doCsdCsMoveEngine(long id, int des) {
            return csdCsMoveEngine.doWork(delegate () { csdCsMoveEngine.id = id; csdCsMoveEngine.des = des; });
        }

        public static TransRes doOne2ManyEngine<O, M>(One2Many<O, M> dto) where O : BaseEntity where M : ChildrenEntity { 
            return one2ManyEngine.doWork(delegate () {
                one2ManyEngine.m = dto.main;
                List<ChildrenEntity> detList = new List<ChildrenEntity>();
                detList.AddRange(dto.detList);
                one2ManyEngine.detList = detList;
                one2ManyEngine.t = typeof(M);
            });

        }
        public static TransRes doStockAddBSEngine(String boxCode) {  
            return stockAddBSEngine.doWork(delegate () {
                stockAddBSEngine.boxCode = boxCode;
             
            });

        }
        public static TransRes doCsd21Engine(String from, String to, long id) { 
            return csd21Engine.doWork(delegate () {
                csd21Engine.from = from;
                csd21Engine.to = to;
                csd21Engine.id = id;
            });

        }
        public static TransRes doCsd2CsEngine(long id, long pid, bool pk = false) { 
            return csd2CsEngine.doWork(delegate () {
                csd2CsEngine.id = id;
                csd2CsEngine.pid = pid;
                csd2CsEngine.pingku = pk;
            });
        }

        public static TransRes doPkStockEngine(long pkId, string add, string del) { 
            return pkStockEngine.doWork(delegate () {
                pkStockEngine.pkId = pkId;
                pkStockEngine.add = add;
                pkStockEngine.del = del;
            });
        } 
        public static TransRes doDooEngine(WhDoo whReceipt) { 
            return dooEngine.doWork(delegate () { dooEngine.doo = whReceipt; }); 
        }
      


        public static TransRes doPkFinshEngine(long pkId) { 
            return pkFinshEngine.doWork(delegate () { pkFinshEngine.pkId = pkId; }); 
        } 
        public static string doPkEngine(long pkId) { 
            TransRes res = pkEngine.doWork(delegate () { pkEngine.pkId = pkId; });
            return res.msg; 
        } 
        public static TransRes doSplitDetEngine(CoreStockDet det) { 
            TransRes res = splitDetEngine.doWork(delegate () { splitDetEngine.det = det; });
            return res;

        }

        public static TransRes doOutDetEngine(long id) {

            TransRes res = outDetEngine.doWork(delegate () { outDetEngine.id = id; });
            return res;
        }
        public static TransRes doChangeCSDEngine(CoreStockDet csd) { 
            TransRes res = changeCSDEngine.doWork(delegate () { changeCSDEngine.csd = csd; });
            return res;

        }


    }
}
